<!--
 * @Author: JiraiyaChen 49619401+JiraiyaChen@users.noreply.github.com
 * @Date: 2024-01-16 16:31:59
 * @LastEditors: JiraiyaChen 49619401+JiraiyaChen@users.noreply.github.com
 * @LastEditTime: 2024-01-17 11:11:04
 * @Description: 部门选择组件
-->

<template>
  <div>
    <div style="display: flex">
      <span>{{ prepend }}</span
      ><el-input
        :value="value | hiddenId"
        :disabled="disabled"
        prefix-icon="el-icon-search"
        :placeholder="placeholder"
        @focus="onFocus"
      />&ensp;<span>{{ append }}</span>
    </div>
    <!-- 部门弹窗 -->
    <dept-dialog
      ref="DeptDialog"
      :multi="multi"
      :selected-ids="value | getIds"
      @onSelect="onSelect"
    />
  </div>
</template>

<script>
import DeptDialog from "./dialog/DeptDialog.vue";
export default {
  name: "FancyUserDeptList",
  components: {
    DeptDialog,
    //   JSelectDept,
  },
  filters: {
    hiddenId(val) {
      return val && val.indexOf("_*_") !== -1 ? val.split("_*_")[0] : val;
    },

    getIds(val) {
      return val && val.indexOf("_*_") !== -1
        ? val.split("_*_")[1].split(",")
        : val.split(",");
    },
  },
  props: {
    value: {
      type: String,
      default: "",
    },
    multi: {
      type: Boolean,
      default: false,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
    placeholder: {
      type: String,
      default: "请选择部门",
    },
    prepend: {
      type: String,
      default: "",
    },
    append: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  methods: {
    onFocus() {
      this.$refs.DeptDialog.dialogVisible = true;
    },
    onSelect(obj) {
      let idsJson = JSON.stringify(obj);
      this.$emit("input", idsJson);
    },
  },
};
</script>

<style lang="scss" scoped></style>
